package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
<#if pojoConfig.vo || pojoConfig.qo>
import org.springframework.web.bind.annotation.GetMapping;
</#if>
import org.springframework.web.bind.annotation.PathVariable;
import pers.yurwisher.rubick.common.wrapper.R;
import lombok.RequiredArgsConstructor;
import ${package.Service}.${table.serviceName};
<#if pojoConfig.fo>
import ${pojoPackage}.fo.${entity}Fo;
import org.springframework.web.bind.annotation.RequestBody;
</#if>
<#if pojoConfig.vo>
import ${pojoPackage}.vo.${entity}Vo;
</#if>
<#if pojoConfig.qo>
import org.springframework.web.bind.annotation.ModelAttribute;
import pers.yurwisher.rubick.common.wrapper.PageR;
import ${pojoPackage}.qo.${entity}Qo;
import ${pojoPackage}.to.${entity}To;
</#if>
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@RequiredArgsConstructor
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

  private final ${table.serviceName} ${entity?uncap_first}Service;

 <#if pojoConfig.fo>
    @PostMapping
    public R<#noparse><</#noparse>String<#noparse>></#noparse> create(@RequestBody ${entity}Fo fo){
        ${entity?uncap_first}Service.create(fo);
        return R.ok();
    }

    @PostMapping("{id}")
    public R<#noparse><</#noparse>String<#noparse>></#noparse> update(@PathVariable(name = "id")${table.commonFields[0].propertyType} id, @RequestBody ${entity}Fo fo){
        ${entity?uncap_first}Service.update(id,fo);
        return R.ok();
    }
 </#if>
 <#if pojoConfig.vo>
    @GetMapping("{id}")
    public R<#noparse><</#noparse>${entity}Vo<#noparse>></#noparse> get(@PathVariable(name = "id")${table.commonFields[0].propertyType} id){
        return R.ok(${entity?uncap_first}Service.get(id));
    }

 </#if>
    @PostMapping("/delete/{id}")
    public R<#noparse><</#noparse>String<#noparse>></#noparse> delete(@PathVariable(name = "id")${table.commonFields[0].propertyType} id){
        ${entity?uncap_first}Service.delete(id);
        return R.ok();
    }

 <#if pojoConfig.qo>
    @GetMapping
    public R<#noparse><PageR<</#noparse>${entity}To<#noparse>>></#noparse> list(@ModelAttribute ${entity}Qo qo){
        return R.ok(${entity?uncap_first}Service.list(qo));
    }

 </#if>
 }
</#if>
